//画作业点
define(["dojo/_base/declare", "esri/toolbars/draw", "esri/graphic", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol", "esri/geometry/Point", "esri/SpatialReference", "dojo/_base/Color", "esri/InfoTemplate"], function(declare, Draw, Graphic, SimpleMarkerSymbol, SimpleLineSymbol, PictureFillSymbol, CartographicLineSymbol, Point, SpatialReference, Color, InfoTemplate) {
    var drawOperSite = declare(null, {
        draw : function(map) {
            var markerSymbol = new SimpleMarkerSymbol();
            markerSymbol.setPath("M16,4.938c-7.732,0-14,4.701-14,10.5c0,1.981,0.741,3.833,2.016,5.414L2,25.272l5.613-1.44c2.339,1.316,5.237,2.106,8.387,2.106c7.732,0,14-4.701,14-10.5S23.732,4.938,16,4.938zM16.868,21.375h-1.969v-1.889h1.969V21.375zM16.772,18.094h-1.777l-0.176-8.083h2.113L16.772,18.094z");
            markerSymbol.setColor(new Color("#00FFFF"));

            var sRef = new SpatialReference({
                wkid : 4326
            });
            dojo.xhrGet({
                url : "/WeatherModif/operatorSite/getOperSites",
                handleAs : "json",

                // content : {
                // key1 : "value1",
                // key2 : "value2",
                // key3 : "value3"
                // },

                load : function(data) {
                    // alert(data);
                    if (data != null && data.result != null) {
                        dojo.forEach(data.result, function(item, index) {
                            // alert(item.operSiteName);
                            var geo = new Point(item.lon, item.lat, sRef);
                            var graphic = new Graphic(geo, markerSymbol);
                            graphic.setAttributes({
                                "XCoord" : geo.x,
                                "YCoord" : geo.y,
                                "Name" : item.operSiteName,
                                "ID" : item.operSiteId
                            });
                            map.graphics.add(graphic);
                        });
                    }
                },
                error : function(data) {

                }
            });

        },

        save : function(map) {
            var j = JSON.stringify([{
                name : "aa",
                age : 12
            }, {
                name : "rr",
                age : 14
            }]);
            alert(j);
            dojo.xhrPost({
                url : "/WeatherModif/operatorSite/saveEdit",
                handleAs : "json",
                content : JSON.stringify(j),
                load : function(data) {

                },
                error : function(data) {

                }
            });
        }
    });
    return drawOperSite;

    function getGraphics(map) {
        var graphicArr = [];
        dojo.forEach(map.graphics.graphics, function(graphic) {
            var g = {
                Name : graphic.attributes["Name"],
                ID : graphic.attributes["ID"],
                XCoord : graphic.attributes["XCoord"],
                YCoord : graphic.attributes["YCoord"],
            };
        });

        return graphicJsonStr;
    }

});
